package com.devmindset.legoframework.usage.client.datasource;

import com.devmindset.legoframework.usage.client.text.UsageTexts;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.DataSourceDateField;
import com.smartgwt.client.data.fields.DataSourceFloatField;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceSequenceField;
import com.smartgwt.client.data.fields.DataSourceTextField;

public class OrderItemLocalDS extends DataSource {

    private static OrderItemLocalDS instance = null;

    public static OrderItemLocalDS getInstance() {
        if (instance == null) {
            instance = new OrderItemLocalDS("orderItemLocalDS");
        }
        return instance;
    }

    public OrderItemLocalDS(String id) {

        setID(id);

        DataSourceSequenceField pkField = new DataSourceSequenceField("pk");
        pkField.setHidden(true);
        pkField.setPrimaryKey(true);

        DataSourceIntegerField orderIdField = new DataSourceIntegerField("orderID", UsageTexts.get().orderItemID());
        orderIdField.setCanEdit(false);
        orderIdField.setPluralTitle("Orders");

        DataSourceTextField itemDescriptionField = new DataSourceTextField("itemDescription", UsageTexts.get().description());
        DataSourceTextField categoryField = new DataSourceTextField("category", UsageTexts.get().category());

        DataSourceDateField shipDateField = new DataSourceDateField("shipDate", UsageTexts.get().shipDate());
        DataSourceIntegerField quantityField = new DataSourceIntegerField("quantity", UsageTexts.get().quantity());
        DataSourceFloatField unitPriceField = new DataSourceFloatField("unitPrice", UsageTexts.get().price());

        setFields(pkField, orderIdField, itemDescriptionField, categoryField, shipDateField, quantityField, unitPriceField);

        setClientOnly(true);        
    }
}